#!/bin/bash
echo "{}" > db.json
echo "admin:123456" > .env

VERSION="1.0.0"
IMAGE_TAG="tiny-json-rest:${VERSION}"
docker build -t "$IMAGE_TAG" .

# 关键信息（tag、时间、大小、摘要）
tag=$(docker image inspect "$IMAGE_TAG" --format '{{if .RepoTags}}{{index .RepoTags 0}}{{else}}<none>{{end}}' 2>/dev/null || echo "<none>")
created=$(docker image inspect "$IMAGE_TAG" --format '{{.Created}}' 2>/dev/null || echo "<unknown>")
size_bytes=$(docker image inspect "$IMAGE_TAG" --format '{{.Size}}' 2>/dev/null || echo "0")
digest=$(docker image inspect "$IMAGE_TAG" --format '{{if .RepoDigests}}{{index .RepoDigests 0}}{{else}}<none>{{end}}' 2>/dev/null || echo "<none>")

if command -v numfmt >/dev/null 2>&1; then
  size_human=$(numfmt --to=iec --suffix=B "$size_bytes")
else
  size_human="${size_bytes} bytes"
fi

echo "构建完成"
echo "Tag: $tag"
echo "时间: $created"
echo "大小: $size_human"
echo "摘要: $digest"